<template>
  <view :style="'--color:' + color + ';--rgbcolor:' + rgbcolor">
    <view :style="'--color:' + color + ';--rgbcolor:' + rgbcolor" class="topbar">
      <text v-for="(item, index) in msg_nav" :key="index" :class="'item ' + (currentTab == item.var ? 'active' : '')"
            :data-var="item.var" @tap="topbarFn">
        <text class="span">{{ item.title }}</text>

        <text v-if="item.newnum > 0" class="b"></text>
      </text>
    </view>
    <view v-if="currentTab == 'ye'" :style="'--color:' + color + ';--rgbcolor:' + rgbcolor" class="tg_my_money_ye">
      <view class="box">
        <view class="dt">
          <text class="i ico"></text>
        </view>
        <view class="dd">
                    <span class="money">
                        {{ D.money }}
                        <text class="font">元</text>
                    </span>
        </view>
        <view class="moneydetail">
          <text class="span">
            <text class="btn2 size1" @tap="ljtxFn">立即提现</text>
          </text>
        </view>
      </view>
    </view>
    <block v-if="currentTab == 'mx'">
      <view v-if="LIST.length > 0" class="my_loveb_mx">
        <block v-for="(dl, idx_list) in LIST" :key="idx_list">
          <view v-for="(item, idx_dl) in dl" :key="idx_dl" :data-uid="item.id" class="dl">
            <view class="dt">
              {{ item.c }}
              <text class="font">{{ item.addtime }}</text>
            </view>

            <view :class="'dd ' + item.class">{{ item.num }}</view>
          </view>
        </block>
      </view>
      <view v-if="nodatabox" class="nodata">
        <image mode="aspectFit" src="/static/res/img/nodata.png"></image>
        暂无信息
      </view>
    </block>
    <block v-if="currentTab == 'tx'">
      <view class="tg_my_money_tx">
        <!--        <view class="h3">-->
        <!--          <text class="b">-->
        <!--            当前-->
        <!--          </text>-->
        <!--        </view>-->
        <view class="isType">
          <view class="isTypeText">提现方式</view>
          <radio-group style="width: 100%" @change="radioChange">
            <label class="li">
              <radio :color="color" :value="1" checked></radio>
              银行卡提现
            </label>
            <!--            <label class="li">-->
            <!--              <radio :color="color" :value="2" disabled></radio>-->
            <!--              微信提现-->
            <!--            </label>-->
          </radio-group>
        </view>
        <view class="withdrawalHer">
          <view class="withdrawalBox">
            <view class="withdrawalBoxLeft">提现金额</view>
            <view class="withdrawalBoxRight">账户余额：
              <text class="font Cf00">￥{{ D.money }}元</text>
            </view>
          </view>
          <view class="inputBox">
            <view class="inputLeft">
              <view class="inputIcon">￥</view>
              <view class="inputCenter">
                <input
                    v-model="withdrawMoney"
                    :maxlength="maxlength"
                    placeholder="请输入提现金额"
                    type="number"
                    @input="change"
                />
              </view>
            </view>
            <view class="inputText" @tap="onAll">
              全部提现
            </view>
          </view>
          <view v-if="D.cook_tx_sxf_bfb > 0" class="herPrice">
            税费:
            <text class="price">{{ commission }}元</text>
          </view>
        </view>
        <!--                <form class="form" @submit="txbtnsubmitFn">-->
        <!--                  <radio-group name="money">-->
        <!--                    <label v-for="(item, index) in D.tx_num_list" :key="index" class="li">-->
        <!--                      <radio :color="color" :value="item"></radio>-->
        <!--                      {{ item }}元-->
        <!--                    </label>-->
        <!--                  </radio-group>-->
        <!--                  &lt;!&ndash;                    <view class="h5" v-if="D.cook_tx_sxf_bfb > 0">提现将收取{{ D.cook_tx_sxf_bfb }}%的税费</view>&ndash;&gt;-->
        <!--                  <button :style="'&#45;&#45;color:' + color + ';&#45;&#45;rgbcolor:' + rgbcolor" class="btn5" formType="submit">立即提现-->
        <!--                  </button>-->
        <!--                </form>-->
        <view class="linebox">
          <view class="line W50"></view>
          <view class="title BAI S14">温馨提醒</view>
        </view>
        <view class="h6">
          <view v-if="D.cook_tx_sxf_bfb > 0">● 提现将收取
            <text class="isRed">{{ D.cook_tx_sxf_bfb }}%</text>
            的税费
          </view>
          <view>● 提现须知:
            <text class="text">
              单次提现最少
              <text class="isRed">{{ minMoney || 10 }}</text>
              元,最多
              <text class="isRed">{{ maxMoney || 10000 }}</text>
              元
            </text>
          </view>
          <view>● 提现金额实际到账
            <text class="isRed">{{ 100 - D.cook_tx_sxf_bfb }}％</text>
            ，有小数的将进行取整处理
          </view>
        </view>
      </view>
      <view class="withdrawalFooter" >
        <view class="footerFlex">
          <view class="footer">
            到账金额:
            <text v-show="amountReceived" class="footerText"> {{ amountReceived }}元</text>
          </view>
          <view class="footerBnt">
            <button :class="['bnt',{'backGer':disabled}]" @tap="txbtnsubmitFn">立即提现</button>
          </view>
        </view>
      </view>
      <view v-if="div_gzh_box" :class="'mask2 ' + mask_class" data-maskid="subscribebox" @tap="mask_closeFn">
        <view class="div_box" style="--div_box_width: 600rpx; --div_box_height: 666rpx" @tap.stop.prevent="emptyFn">
          <view class="closebtm ico" data-maskid="subscribebox" @tap.stop.prevent="mask_closeFn"></view>
          <view class="h1">长按识别关注公众号</view>
          <view class="kf_wxpic">
            <image :showMenuByLongpress="true" :src="D.wx_gzh_ewm"></image>
          </view>
          <view class="kf_text">
            <text class="ico dui"></text>
            关注成功才能打款给您微信零钱哦
          </view>
        </view>
      </view>
    </block>
  </view>
</template>

<script>
var t;
var a;
var e = require('../../@babel/runtime/helpers/defineProperty');
var n = require('../../res/www.a9a.cn.js');
var app = getApp();
var o = 2;
var s = true;
export default {
  data() {
    return {
      color: '',
      rgbcolor: '',
      currentTab: '',
      loading_ico_flag: false,
      loading_flag: false,
      loading_str: '',
      nTitle: '',
      D: {
        money: '',
        tx_num_list: [],
        cook_tx_sxf_bfb: 0,
        wx_gzh_ewm: '',
        cook_tg_gzh_openid: '',
      },
      tx_type: 1,
      withdrawMoney: '',
      maxlength: 8,
      disabled: false,
      maxMoney: 10000, // 最大提现
      minMoney: 1, // 最小提现
      msg_nav: '',
      div_gzh_box: '',
      MB: '',
      nodatabox: false,
      mask_class: '',
      div_myinfo_form: false,
      LIST: [],
      idx_list: [],
      dl: [],
      idx_dl: 0
    };
  },
  onLoad: function (t) {
    var that = this;
    var o = this;
    app.globalData.get_config('_ZEAI').then(function (t) {
      o.setData({
        color: app.globalData._ZEAI.color,
        rgbcolor: n.c16_rgb(app.globalData._ZEAI.color)
      });
    });
    var s = 'ye' == t.currentTab ? 'ye' : t.currentTab;
    a = t.t;
    'ye' == s ||
    app.globalData.empty(s) ||
    this.setData({
      currentTab: s
    });
  },
  onShow() {
    var that = this;
    app.globalData.get_openid().then(function (t) {
      that.init();
    });
  },
  computed: {
    // 手续费
    commission() {
      if (this.withdrawMoney === "") return 0
      let commissionNum = 0;
      const tixiansd = +this.D.cook_tx_sxf_bfb * 0.01
      commissionNum = Math.round((this.withdrawMoney * tixiansd) * 100) / 100;
      return commissionNum
    },
    // 到账金额
    amountReceived() {
      if (this.withdrawMoney < +this.minMoney) return 0
      return Math.round((this.withdrawMoney - this.commission) * 100) / 100;
    },
  },
  onPullDownRefresh: function () {
    var that = this;
    uni.vibrateShort({
      type: 'heavy'
    });
    setTimeout(function () {
      that.setData({
        currentTab: 'ye'
      });
      o = 2;
      a = '';
      uni.stopPullDownRefresh();
      that.init();
    }, 500);
  },
  onReachBottom: function () {
    if (0 != this.currentTab) {
      var that = this;
      var r = this.LIST;
      if (s) {
        s = false;
        that.setData({
          loading_ico_flag: true
        });
        app.globalData.ajax({
          url: 'tg.php',
          data: {
            submitok: 'MY_MONEY_MX',
            p: o,
            t: a,
            openid: t.openid
          },
          success: function (t) {
            var a = t.LIST;
            if (a.length < 1) {
              that.setData({
                loading_flag: true,
                loading_ico_flag: false,
                loading_str: '已全部加载完成'
              });
              return void (s = false);
            }
            that.setData(e({}, 'LIST[' + r.length + ']', a));
            o += 1;
            s = true;
          }
        });
      }
    }
  },
  onShareAppMessage: function (t) {
    return {
      imageUrl: this.SHARE.imgurl,
      title: this.SHARE.title,
      path: '/hnPages/tg/my_money'
    };
  },
  onShareTimeline: function () {
    return {
      imageUrl: this.SHARE.imgurl,
      title: this.SHARE.title,
      query: '',
      path: '/hnPages/tg/my_money'
    };
  },
  methods: {
    topbarFn: function (t) {
      var a = t.currentTarget.dataset.var;
      a = app.globalData.empty(a) ? 'ye' : a;
      this.setData({
        currentTab: a
      });
      if ('mx' == a) {
        this.get_data();
      } else if (this.currentTab === 'tx' && this.D.bank_type === '0') {
        uni.showModal({
          content: '请先完善银行卡信息',
          confirmColor: this.color,
          confirmText: '立即完善',
          cancelText: '取消',
          showCancel: true,
          success: function (res) {
            if (res.confirm) {
              uni.navigateTo({
                url: '/hnPages/tg/my_info',
              })
            } else if (res.cancel) {
              console.log('用户点击取消');
              uni.navigateBack({
                delta: -1
              });
            }
          }
        })
      }
    },
    radioChange(evt) {
      this.tx_type = +evt.detail.value;
    },

    convertToNumber(formattedNumber) {
      // 移除所有逗号并转换为数字类型
      return parseFloat(formattedNumber.replace(/,/g, ''));
    },
    init: function () {
      var that = this;
      uni.showNavigationBarLoading();
      t = uni.getStorageSync('COOK_U');
      app.globalData.ajax({
        url: 'tg.php',
        data: {
          submitok: 'MY_MONEY',
          openid: t.openid
        },
        success: function (t) {
          var e = app.globalData.empty(that.currentTab) ? 'ye' : that.currentTab;
          that.setData({
            currentTab: e
          });
          if (1 == t.flag) {
            var n = !!app.globalData.empty(t.D.cook_tg_gzh_openid);
            that.setData({
              nTitle: t.nTitle,
              D: t.D,
              msg_nav: t.msg_nav,
              div_gzh_box: n,
              MB: t.MB,
            });
            that.D.money = that.convertToNumber(that.D.money)
            if (that.currentTab === 'tx' && that.D.bank_type === '0') {
              uni.showModal({
                content: '请先完善银行卡信息',
                confirmColor: that.color,
                confirmText: '立即完善',
                cancelText: '取消',
                showCancel: true,
                success: function (res) {
                  if (res.confirm) {
                    uni.navigateTo({
                      url: '/hnPages/tg/my_info',
                    })
                    // 执行确定操作
                  } else if (res.cancel) {
                    uni.navigateBack({
                      delta: -1
                    });
                  }
                }
              })
            }
            uni.setNavigationBarTitle({
              title: t.nTitle
            });
            if ('mx' == e) {
              that.get_data();
            }
          } else {
            uni.showToast({
              title: t.msg,
              icon: 'none',
              mask: true
            });
          }
          uni.hideNavigationBarLoading();
        }
      });
    },

    txbtnsubmitFn: function () {
      const that = this
      n.empty(that.MB) || app.globalData.openSetting(that.MB);
      t = uni.getStorageSync('COOK_U');
      if (app.globalData.empty(this.D.cook_tg_gzh_openid)) {
        this.setData({
          div_gzh_box: true
        });
      } else {
        const that = this;
        if (!that.disabled) return;
        const s = that.withdrawMoney;
        if (app.globalData.empty(s)) {
          return void uni.showToast({
            title: '请填写提现金额',
            icon: 'none',
            mask: true
          });
        }
        app.globalData.ajax({
          url: 'tg.php',
          data: {
            submitok: 'MY_MONEY_TX_update',
            tx_money: s,
            tx_type: that.tx_type,
            openid: t.openid
          },
          success: function (t) {
            1 == t.flag
                ? uni.showModal({
                  content: t.msg,
                  confirmColor: that.color,
                  confirmText: '朕知道了',
                  showCancel: false,
                  success: function (a) {
                    uni.vibrateShort({
                      type: 'heavy'
                    });
                    that.setData(
                        e(
                            {
                              currentTab: 'mx'
                            },
                            'D.money',
                            t.money
                        )
                    );
                    that.get_data();
                  }
                })
                : uni.showToast({
                  title: t.msg,
                  icon: 'none',
                  mask: true
                });
            uni.hideNavigationBarLoading();
          }
        });
      }
    },

    get_data: function () {
      s = false;
      var that = this;
      t = uni.getStorageSync('COOK_U');
      uni.showNavigationBarLoading();
      app.globalData.ajax({
        url: 'tg.php',
        data: {
          submitok: 'MY_MONEY_MX',
          t: a,
          openid: t.openid
        },
        success: function (t) {
          var a = t.LIST;
          if (1 == t.flag) {
            var i;
            if (a.length >= 15) {
              that.setData({
                loading_flag: true,
                loading_ico_flag: true
              });
            }
            if (0 == a.length) {
              that.setData({
                loading_flag: false,
                nodatabox: true
              });
            } else {
              that.setData((e((i = {}), 'LIST[0]', a), e(i, 'nodatabox', false), e(i, 'loading_flag', false), i));
            }
            s = true;
          } else {
            uni.showModal({
              content: t.msg,
              confirmColor: that.color,
              confirmText: '朕知道了',
              showCancel: false,
              success: function (t) {
              }
            });
          }
          uni.hideNavigationBarLoading();
        }
      });
    },

    ljtxFn: function () {
      n.empty(this.MB) || app.globalData.openSetting(this.MB);
      this.setData({
        currentTab: 'tx'
      });
    },

    mask_closeFn: function (t) {
      var that = this;
      var n = t.currentTarget.dataset.maskid;
      this.setData({
        mask_class: 'alpha100_0'
      });
      setTimeout(function () {
        var t;
        that.setData((e((t = {}), n, false), e(t, 'mask_class', 'alpha0_100'), e(t, 'div_gzh_box', false), t));
      }, 500);
    },

    emptyFn: function () {
    },

    my_info_closeFn: function () {
      this.setData({
        div_myinfo_form: false
      });
    },
    // 限制输入长度
    change(val) {
      const Valenzuela = val.detail.value;
      if (this.withdrawMoney === '') return this.disabled = false
      let {
        value,
        maxlength
      } = this.returnLength(Valenzuela, this.maxlength)
      if (+Valenzuela >= +this.maxMoney) {
        value = this.maxMoney
        maxlength = ('' + value).length
        uni.showToast({
          title: '单笔最大提现值'+ this.maxMoney,
          icon: 'none',
          mask: true
        });
      } else if (+Valenzuela > +this.D.money) {
        value = this.D.money
        maxlength = this.D.money.length
      }
      this.maxlength = maxlength
      // && this.money <= this.shop.money
      this.disabled = value >= this.minMoney && value <= this.maxMoney && value <= this.D.money;
      this.withdrawMoney = value
    },
    // 判断长度
    returnLength(data, length) {
      const _m = String(data).split('.')[1]
      const _th = String(data).split('.')[0].length
      if (_m) {
        if (_m.length >= 2) {
          length = _th + 3
        }
      } else {
        length = 8
      }
      return {
        value: !data ? '' : +data,
        maxlength: +length
      }


    },
    // 全部提现
    onAll() {
      if (+this.D.money >= +this.maxMoney) {
        this.withdrawMoney = this.maxMoney
        uni.showToast({
          title: '单笔最大提现值'+ this.maxMoney,
          icon: 'none',
          mask: true
        });
      } else {
        this.withdrawMoney = this.D.money
      }
      this.disabled = this.withdrawMoney >= this.minMoney && this.withdrawMoney <= this.maxMoney && this.withdrawMoney <= this.D.money;
    },
  }
};
</script>
<style lang="scss" scoped>
@import 'my_money.scss';
</style>
